package com.tsing.common.framwork.mapper;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

/**
 * 实现数据库类型与Java类型的映射
 */
public class TypeConstant {
	/***
	 * 数据库类型和Java类型映射，key为数据库类型，value为Java类型
	 */
	private static final Map<String, Class<?>> typeMap = new HashMap<String, Class<?>>();

	static {
		typeMap.put("BIGINT", Long.class);
		typeMap.put("INT", Long.class);
		typeMap.put("INT UNSIGNED", Long.class);
		typeMap.put("VARCHAR", String.class);
		typeMap.put("CHAR", String.class);
		typeMap.put("TEXT", String.class);
		typeMap.put("DATETIME", LocalDateTime.class);
		typeMap.put("DOUBLE", Double.class);
		typeMap.put("DECIMAL", Double.class);
		typeMap.put("TINYINT", Integer.class);
		typeMap.put("TINYINT UNSIGNED", Integer.class);
		typeMap.put("BIT", Boolean.class);
		typeMap.put("TIMESTAMP", LocalDateTime.class);
		typeMap.put("LONGTEXT",String.class);
		typeMap.put("BIGINT UNSIGNED",Long.class);

	}

	public static void addType(String columnType, Class<?> javaType) {
		typeMap.put(columnType, javaType);
	}

	public static Class<?> getJavaType(String columnType) {
		return typeMap.get(columnType);
	}
}
